package com.sleepcamel.resteasyConfigurator.model.command;

import java.util.Arrays;

import org.eclipse.jface.action.Action;

import com.sleepcamel.rest.domain.TreeNode;
import com.sleepcamel.resteasyConfigurator.util.ImageDescriptorProvider;

public class AddNodeAction extends Action {
	
	private TreeNode node;
	private Class<? extends TreeNode> childClass;

	public AddNodeAction(TreeNode node, Class<? extends TreeNode> childClass, String entityNameAccelerator, String imageFileName) {
		this.node = node;
		this.childClass = childClass;
		setText("New "+entityNameAccelerator);
		setImageDescriptor(ImageDescriptorProvider.getImageDescriptor(imageFileName));
	}

	@SuppressWarnings("unchecked")
	@Override
	public void run() {
		AddTreeNodeCommand addTreeNodeCommand = new AddTreeNodeCommand();
		addTreeNodeCommand.setReceiver(node);
		addTreeNodeCommand.setArguments(Arrays.asList(childClass));
		addTreeNodeCommand.execute();
	}

}
